package com.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

//统一响应体
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer code;//状态码
    private String msg;//字符串内容
    private T data;//对象

    //请求失败，服务器报错的常量
    public static final Result<Void> FAIL = new Result<>(500, "fail", null);
    //请求成功无数据返回的方法
    public static Result<Void> ok(){
        return new Result<>(200, "success" ,null);
    }
    //请求成功有数据返回的方法
    public static <T> Result<T> ok(T data){
        return new Result<>(200, "success",data);
    }
    public static <T> Result<T> ok(String msg){
        return new Result<>(200, msg , null);
    }
}
